package com.leoman.spinningmachine.tab3;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.TextView;

import com.leoman.spinningmachine.R;
import com.leoman.spinningmachine.base.BaseActivity;
import com.leoman.spinningmachine.bean.PermissionBean;
import com.leoman.spinningmachine.http.APIResponse;
import com.leoman.spinningmachine.http.WebServiceApi;
import com.leoman.spinningmachine.util.SharedPreferencesUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2018-05-07.
 */
public class MyPermissionActivity extends BaseActivity {

    @BindView(R.id.rv)
    RecyclerView recyclerView;

    @BindView(R.id.tv_permision_num)
    TextView tv_permision_num;

    private PermissionAdapter adapter;
    private String token;
    private List<PermissionBean> permissionList = new ArrayList<>();

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.ac_my_permision;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        initTitle("我的权限");
        adapter = new PermissionAdapter(R.layout.item_permission, null);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(adapter);
    }

    @Override
    protected void initData() {
        token = SharedPreferencesUtils.getInstance().getString("token");
        WebServiceApi.getInstance().queryMyPermission(token, this, 1);

    }

    @Override
    public void OnSuccessData(APIResponse apiResponse, Integer tag) {
        super.OnSuccessData(apiResponse, tag);
        if (tag == 1) {
            permissionList = apiResponse.data.list;
            adapter.setData(apiResponse.data.list);
            tv_permision_num.setText("" + (permissionList == null ? 0 : permissionList.size()));
        }
    }
}
